﻿using Cmp.Web.Common;
using Cmp.Web.IRepository;
using Cmp.Web.IService;
using Cmp.Web.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cmp.Web.Repository
{
    /// <summary>
    /// 挂号数据接口
    /// </summary>
    public class RegisterProvide : DbContext<RegisterInfo>, IRegisterProvide
    {
        public Task<RegisterInfo> GetRegisterInfoByRegisterNumber(string RegisterNumber, out ExceptionAll exception)
        {
            exception = new ExceptionAll();
            try
            {
                Task.FromResult(Db.Queryable<RegisterInfo>().Where(x => x.RegisterNumber == RegisterNumber).ToList());
            }
            catch (Exception ex)
            {
                exception.errMsg = ex.Message;
                exception.Action = System.Reflection.MethodBase.GetCurrentMethod()!.Name;
                exception.errMsgId = ErrorType.MyInterfaceError;
                exception.Exception = ex;
            }
            return null;
        }

        public Task<List<RegisterInfo>> GetRegisterInfoListByPatientId(string PatientId, string RegisterTime, out ExceptionAll exception)
        {
            exception = new ExceptionAll();
            try
            {
                return Task.FromResult(Db.Queryable<RegisterInfo>().Where(x => x.RegisterPatientId == PatientId && x.RegisterTime == RegisterTime).ToList());
            }
            catch (Exception ex)
            {
                exception.errMsg = ex.Message;
                exception.Action = System.Reflection.MethodBase.GetCurrentMethod()!.Name;
                exception.errMsgId = ErrorType.MyInterfaceError;
                exception.Exception = ex;
            }
            return null;
        }

        public Task<List<RegisterInfo>> GetRegisterInfoListByTime(string RegisterTime, out ExceptionAll exception)
        {
            exception = new ExceptionAll();
            try
            {
                return Task.FromResult(Db.Queryable<RegisterInfo>().Where(x => x.RegisterTime == RegisterTime).ToList());
            }
            catch (Exception ex)
            {
                exception.errMsg = ex.Message;
                exception.Action = System.Reflection.MethodBase.GetCurrentMethod()!.Name;
                exception.errMsgId = ErrorType.MyInterfaceError;
                exception.Exception = ex;
            }
            return null;
        }

        public Task<bool> RegisterConfirm(RegisterInfo register, out ExceptionAll exception)
        {
            exception = new ExceptionAll();
            try
            {
                return Task.FromResult(Db.Insertable<RegisterInfo>(register).ExecuteCommand() > 0);
            }
            catch (Exception ex)
            {
                exception.errMsg = ex.Message;
                exception.Action = System.Reflection.MethodBase.GetCurrentMethod()!.Name;
                exception.errMsgId = ErrorType.MyInterfaceError;
                exception.Exception = ex;
            }
            return Task.FromResult(false);
        }

        public Task<string> RegisterPre(RegisterInfo register, out ExceptionAll exception)
        {
            throw new NotImplementedException();
        }
    }
}
